package xyz.zdsoft.course_manage_module.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import xyz.zdsoft.common.utils.JwtUtils;
import xyz.zdsoft.common.utils.ResultBody;
import xyz.zdsoft.course_manage_module.bo.CourseInfoBo;
import xyz.zdsoft.course_manage_module.mapper.StudentCourseMapper;
import xyz.zdsoft.course_manage_module.service.StudentCourseService;
import xyz.zdsoft.course_manage_module.utils.NotNull;
import xyz.zdsoft.course_manage_module.vo.CourseInfoVo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-07-22 周四
 * @time 14:29
 * @description
 */
@Service
public class StudentCourseServiceImpl implements StudentCourseService {

    @Resource
    private StudentCourseMapper studentCourseMapper;


    @Override
    public ResultBody queryCourseList(CourseInfoBo courseInfoBo, HttpServletRequest request) {

//        获取学生id
        Integer studentId = Integer.parseInt(JwtUtils.getMemberIdByJwtToken(request));
        courseInfoBo.setStudentId(studentId);
        courseInfoBo.setTeacherId(null);

        Page<CourseInfoVo> page = new Page<>(courseInfoBo.getPageNumber(), courseInfoBo.getPageSize());

        QueryWrapper<CourseInfoVo> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq(NotNull.judge(courseInfoBo.getStudentId()), "student_id", courseInfoBo.getStudentId());
        queryWrapper.like(NotNull.judge(courseInfoBo.getCourseName()), "course_name", courseInfoBo.getCourseName());
        queryWrapper.like(NotNull.judge(courseInfoBo.getTrainTeacher()), "train_teacher", courseInfoBo.getTrainTeacher());
        queryWrapper.like(NotNull.judge(courseInfoBo.getDutyTeacher()), "duty_teacher", courseInfoBo.getDutyTeacher());
        queryWrapper.ge(NotNull.judge(courseInfoBo.getStartDate()), "project_date", courseInfoBo.getStartDate());
        queryWrapper.le(NotNull.judge(courseInfoBo.getEndDate()), "project_date", courseInfoBo.getEndDate());
//        queryWrapper.between(NotNull.judge(courseInfoBo.getSignInTime()) && NotNull.judge(courseInfoBo.getSignOutTime()),
//                "sign_in_time,sign_out_time", courseInfoBo.getSignInTime(), courseInfoBo.getSignOutTime());

        return ResultBody.success(studentCourseMapper.queryCourse(page, queryWrapper));

    }

//    @Override
//    public ResultBody queryCourseName(String token) {
//        return null;
//    }

}
